package com.zsck.zsgy.ui.main

import android.os.Bundle
import com.blankj.utilcode.util.ResourceUtils
import com.google.android.material.tabs.TabLayout
import com.zsck.commonbase.widget.TabLayoutMediator
import com.zsck.zsgy.R
import com.zsck.zsgy.base.BaseFragment
import com.zsck.zsgy.base.BaseViewModel
import com.zsck.zsgy.databinding.FragmentHostBinding
import com.zsck.zsgy.ui.main.adapter.NavPagerAdapter
import com.zsck.zsgy.util.Constants

/**
 * 主页fragment
 */
class NavHostFragment : BaseFragment<BaseViewModel, FragmentHostBinding>() {
    var bottomBar: TabLayout? = null

    var mAdapter :NavPagerAdapter?=null
    override fun initView(savedInstanceState: Bundle?) {
        bottomBar = binding.bottomBar
        mAdapter=  NavPagerAdapter(this)
        binding.vpHome.isUserInputEnabled=false//true:滑动，false：禁止滑动
        binding.vpHome.adapter=mAdapter
        var tabLayoutMediator: TabLayoutMediator =
            TabLayoutMediator(bottomBar!!, binding.vpHome, object :
                TabLayoutMediator.OnConfigureTabCallback {
                override fun onConfigureTab(tab: TabLayout.Tab, position: Int) {
                    tab.text =Constants.navName!![position]
                    when(position){
                        0 -> tab.setIcon(ResourceUtils.getDrawable(R.drawable.icon_home))
                        1 -> tab.setIcon(ResourceUtils.getDrawable(R.drawable.icon_find))
                        2 -> tab.setIcon(ResourceUtils.getDrawable(R.drawable.icon_simple))
                        3 -> tab.setIcon(ResourceUtils.getDrawable(R.drawable.icon_home))
                    }
                }
            })
        tabLayoutMediator.attach()


    }


    override fun layoutId(): Int {
        return R.layout.fragment_host
    }

    override fun lazyLoad() {

    }

}
